Skip to content

Fix dependent function setup for capture checking #16542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

Linyxus
Copy link
Contributor

@Linyxus Linyxus commented Dec 16, 2022

Fixes #15925.

This issue is caused by a bug in mapInferred during CC Setup. In this function we convert all top-level non-dependent functions to its dependent counterpart. However, it does not correctly handle the case when the type is an alias to function types. The problematic case in the pattern matching:

case tp @ AppliedType(tycon, args) =>
  val tycon1 = this(tycon)
  if defn.isNonRefinedFunction(tp) then
    // Convert toplevel generic function types to dependent functions
    val args0 = args.init
    var res0 = args.last
    val args1 = mapNested(args0)
    val res1 = this(res0)
    // ... do the conversion

It retrieves the argument and the result type of the function directly from the applied type arguments. This works for function classes. However, if the type here is a type alias to the function, e.g. type Lazy[X] = Unit => X, it is still recognized as a function (since defn.isNonRefinedFunction does dealiasing) but it is incorrect to get the argument and result type of the function from the type parameter list here (which is just X :: Nil).

To fix this, we will dealias the type and recurse when it is an alias to the function type.

@Linyxus Linyxus requested a review from odersky December 16, 2022 15:27
@Linyxus Linyxus assigned odersky and unassigned odersky Dec 16, 2022
@odersky odersky merged commit 0397de1 into scala:main Dec 20, 2022
@odersky odersky deleted the fix-i15925 branch December 20, 2022 15:12
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture checker triggers AssertionError on function application
3 participants